<%@ page contentType="text/html; charset=utf-8" language="java" %>
<%@ include file="/system/include/taglib.jsp"%>
<%@ page import="java.util.*" %>
<%@ page import="com.zhongkai.model.config.Menu" %>
<%@ page import="com.zhongkai.model.config.Button" %>
<html>
<head>
<base href="${pageScope.basePath }">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>角色权限管理</title>
<link type="text/css" rel="stylesheet" href="system/css/style.css" />
<script type="text/javascript" language="javascript" src="system/js/public.js"></script>
<script type="text/javascript" language="javascript" src="system/js/jquery-1.4.2.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
	$("#checkAll").click(function(){
		$("input[name='actionKey']").attr("checked",true);
	});
	$("#checkNon").click(function(){
		$("input[name='actionKey']").attr("checked",false);
	});
});
function reback(url){
	location.href=url;
}
function Menu(menuId,menuName,actionKey){
	this.menuId=menuId;
	this.menuName=menuName;
	this.actionKey=actionKey;
}
function Button(buttonId,buttonName,actionKey){
	this.buttonId=buttonId;
	this.buttonName=buttonName;
	this.actionKey=actionKey;
}
var menuArray1=new Array();
var menuArray2=new Array();
var menuArray3=new Array();
var buttonArray=new Array();
function menuClick(menuId,level,parent1,parent2){
	if(level==1 && !$$("menu"+menuId).checked){
		for(var i=0;i<menuArray1.length;i++){
			if(menuArray1[i].menuId==menuId){
				for(var j=0;j<menuArray2[i].length;j++){
					$$("menu"+menuArray2[i][j].menuId).checked=false;
					for(var k=0;k<menuArray3[i][j].length;k++){
						$$("menu"+menuArray3[i][j][k].menuId).checked=false;
					}
				}
				return;
			}
		}
	}
	if(level==2 && !$$("menu"+menuId).checked){
		for(var i=0;i<menuArray2.length;i++){
			for(var j=0;j<menuArray2[i].length;j++){
				if(menuArray2[i][j].menuId==menuId){
					for(var k=0;k<menuArray3[i][j].length;k++){
						$$("menu"+menuArray3[i][j][k].menuId).checked=false;
					}
					return;
				}
			}
		}
	}
	if(level==2 && $$("menu"+menuId).checked && !$$("menu"+parent1).checked){
		$$("menu"+parent1).checked=true;
	}
	if(level==3 && $$("menu"+menuId).checked){
		if(!$$("menu"+parent2).checked)
			$$("menu"+parent2).checked=true;
		if(!$$("menu"+parent1).checked)
			$$("menu"+parent1).checked=true;
	}
}
var p1,p2,p3;
</script>
</head>
<body>
<mytag:View name="role" table="com.zhongkai.model.config.Role" id="${param.rid }"></mytag:View>
<div class="main">
	<div class="position">当前位置: <a href="sysadm/desktop.jsp">桌 面</a> → <a href="rolelist.jsp">角色管理</a> → 权限管理</div>
	<div class="mainbody">
		<div class="toolbar">
			工具栏：
			<input id="checkAll" type="button" value="全选" class="system_button" />
			<input id="checkNon" type="button" value="全不选" class="system_button" />
			<input type="button" value="返回" class="system_button" onclick="reback('rolelist.jsp')" />
		</div>
		<div class="operate_info">
			<font color="#FF0000"><label id="explaininfo">当前选择角色：${role.roleName }</label></font>
		</div>
		<div class="table">
			<form action="system/config/role_manage_action.do" method="post">
				<input name="roleId" type="hidden" value="${role.roleId }" />
				<table width="100%" border="0" cellpadding="1" cellspacing="1" class="table_list">
					<tr>
						<td width="50%" style="vertical-align:top;border:none;">
							<table width="100%" border="0" cellpadding="1" cellspacing="1" class="table_list">
								<tr>
									<th>菜单权限</th>
								</tr>
								<mytag:listMenuForActionSet menu1="menuList1" menu2="menuList2" menu3="menuList3"></mytag:listMenuForActionSet>
								<mytag:List field="actionKey" name="menuActionList" table="Action">actionType=0 and roleId=${role.roleId }</mytag:List>
								<%
									Object[] menuActionKeys=null;
									List menuActionList=(List)pageContext.getAttribute("menuActionList");
									if(menuActionList!=null && menuActionList.size()>0){
										menuActionKeys=menuActionList.toArray();
										Arrays.sort(menuActionKeys);
									}
								%>
								<logic:iterate id="menu1" name="menuList1" indexId="menuIndex1">
									<tr onMouseOver="mouseOver(this)" onMouseOut="mouseOut(this)">
										<td>
											<input name="actionKey" id="menu${menu1.menuId }" type="checkbox" onclick="menuClick(${menu1.menuId },1,0,0)" value="${menu1.actionKey }" 
											<%
												Menu menu01=(Menu)pageContext.getAttribute("menu1");
												if(menuActionKeys!=null && Arrays.binarySearch(menuActionKeys,menu01.getActionKey())>-1)
													out.print("checked");
											%>
											 />${menu1.menuName }
											<input name="${menu1.actionKey }" type="hidden" value="0" />
											<script type="text/javascript" language="javascript">
												menuArray1[menuArray1.length]=new Menu("${menu1.menuId }","${menu1.menuName }","${menu1.actionKey }");
											</script>
										</td>
									</tr>
									<script type="text/javascript" language="javascript">
										p1=menuArray1.length-1;
										menuArray2[p1]=new Array();
										menuArray3[p1]=new Array();
									</script>
									<logic:iterate id="menu2" name="menuList2" indexId="menuIndex2">
										<c:if test="${menu2.menuParent==menu1.menuId }">
											<tr onMouseOver="mouseOver(this)" onMouseOut="mouseOut(this)">
												<td style="padding-left:20px;">
													∟<input name="actionKey" id="menu${menu2.menuId }" type="checkbox" onclick="menuClick(${menu2.menuId },2,${menu2.menuParent },0)" value="${menu2.actionKey }" 
													<%
														Menu menu02=(Menu)pageContext.getAttribute("menu2");
														if(menuActionKeys!=null && Arrays.binarySearch(menuActionKeys,menu02.getActionKey())>-1)
															out.print("checked");
													%>
													 />${menu2.menuName }
													<input name="${menu2.actionKey }" type="hidden" value="0" />
													<script type="text/javascript" language="javascript">
														menuArray2[menuArray1.length-1][menuArray2[menuArray1.length-1].length]=new Menu("${menu2.menuId }","${menu2.menuName }","${menu2.actionKey }");
													</script>
												</td>
											</tr>
											<script type="text/javascript" language="javascript">
												p2=menuArray2[p1].length-1;
												menuArray3[p1][p2]=new Array();
											</script>
											<logic:iterate id="menu3" name="menuList3" indexId="menuIndex3">
												<c:if test="${menu3.menuParent==menu2.menuId }">
													<tr onMouseOver="mouseOver(this)" onMouseOut="mouseOut(this)">
														<td style="padding-left:50px;">
															∟<input name="actionKey" id="menu${menu3.menuId }" type="checkbox" onclick="menuClick(${menu3.menuId },3,${menu2.menuParent },${menu3.menuParent })" value="${menu3.actionKey }" 
															<%
																Menu menu03=(Menu)pageContext.getAttribute("menu3");
																if(menuActionKeys!=null && Arrays.binarySearch(menuActionKeys,menu03.getActionKey())>-1)
																	out.print("checked");
															%>
															 />${menu3.menuName }
															<input name="${menu3.actionKey }" type="hidden" value="0" />
															<script type="text/javascript" language="javascript">
																menuArray3[p1][p2][menuArray3[p1][p2].length]=new Menu("${menu3.menuId }","${menu3.menuName }","${menu3.actionKey }");
															</script>
														</td>
													</tr>
												</c:if>
											</logic:iterate>
										</c:if>
									</logic:iterate>
								</logic:iterate>
							</table>
						</td>
						<td style="vertical-align:top;border:none;">
							<table width="100%" border="0" cellpadding="1" cellspacing="1" class="table_list">
								<tr>
									<th colspan="2">操作权限</th>
								</tr>
								<mytag:List name="buttonList" table="Button"></mytag:List>
								<mytag:List field="actionKey" name="buttonActionList" table="Action">actionType=1 and roleId=${role.roleId }</mytag:List>
								<%
									Object[] buttonActionKeys=null;
									List buttonActionList=(List)pageContext.getAttribute("buttonActionList");
									if(buttonActionList!=null && buttonActionList.size()>0){
										buttonActionKeys=buttonActionList.toArray();
										Arrays.sort(buttonActionKeys);
									}
								%>
								<logic:iterate id="button" name="buttonList">
									<tr onMouseOver="mouseOver(this)" onMouseOut="mouseOut(this)">
										<td>
											<input name="actionKey" type="checkbox" value="${button.actionKey }" 
											<%
												Button buttonMatch=(Button)pageContext.getAttribute("button");
												if(buttonActionKeys!=null && Arrays.binarySearch(buttonActionKeys,buttonMatch.getActionKey())>-1)
													out.print("checked");
											%>
											 />${button.buttonNote }
											<input name="${button.actionKey }" type="hidden" value="1" />
										</td>
									</tr>
								</logic:iterate>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="2" class="form_button" style="padding-top:10px;">
							<input type="submit" value="保存" />
							<input type="reset" value="重置" />
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</div>
</body>
</html>
